package Lintcode;

import java.util.Scanner;

/**
 * Question: https://www.lintcode.com/zh-cn/problem/rotate-string/
 * Solution:
 * Time: 2018/4/30
 * Coder: Ksxy 
**/
public class Rotate_string {
    static Scanner scanner = null;

    static {
        scanner = new Scanner(System.in);
    }

    public static void main(String[] args) {
        String str = scanner.nextLine();
        int offset = scanner.nextInt();
        char[] array = str.toCharArray();
        rotateString(array, offset);
        for (char t: array) {
            System.out.print(t+" ");
        }
    }

    public static void rotateString(char[] str, int offset) {
        int len = str.length;
        int changeCount = 0;
        for(int i=0; changeCount < len-1; i++){
            int temp_index = i;
            int start_index = i;
            char temp = str[temp_index];
            do{
               int index = (temp_index+offset)%len;
               str[start_index] = str[index];
               str[index] = temp;
               temp = str[start_index];
               temp_index = index;
               changeCount++;
            }while (temp_index != start_index);

            str[start_index] = temp;
        }
    }
}
